package com.liyongzhen.service.impl;

import com.liyongzhen.mapper.EmpMapper;
import com.liyongzhen.pojo.Emp;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.liyongzhen.pojo.PageBean;
import com.liyongzhen.service.EmpService;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServicelmpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public PageBean page(Integer page, Integer pageSize,String name, Short gender, LocalDate begin, LocalDate end) {
        //获取总记录数
        Long count = empMapper.count();
        //获取分页查询结果
        Integer start = (page-1)*pageSize;
        List<Emp> empList = empMapper.page(start,pageSize,name,gender,begin,end);
        //封装Pagebean对象
        PageBean pageBean=new PageBean(count,empList);
        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void save(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getById(Integer id) {
        return empMapper.getById(id);
    }

    @Override
    public void updata(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.updata(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.getByUsernameAndPassword(emp);
    }
}
